package cn.net.yugu.doraemon.sharding.strategy.impl;

import cn.net.yugu.doraemon.sharding.model.ShardContext;
import cn.net.yugu.doraemon.sharding.strategy.ITableShardStrategy;

/**
 * @author wanghongli
 * @date 2023/12/16 14:42
 * @description IdTableShardStrategy
 **/
public class IdTableShardStrategy implements ITableShardStrategy {
    @Override
    public String generateTableName(String tableNamePrefix, ShardContext shardContext) {
        verifyTableNamePrefix(tableNamePrefix);
        long id = (long)shardContext.getShardValue();
        return (tableNamePrefix + "_" + (id % shardContext.getTableSize())).intern();
    }
}
